package com.dyh.service.user;

import com.dyh.dao.UserDao;
import com.dyh.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDao userDao;

    public void addUser(User user){
        userDao.addUser(user);
    }

    public void deleteUser(int id){
        userDao.deleteUser(id);
    }

    public void updateUser(User user){
        userDao.updateUser(user);
    }

    public List<User> queryUserList(){
        return userDao.queryUserList();
    }

    public User queryUserById(int id){
        return userDao.queryUserById(id);
    }

    @Override
    public User queryUserByName(String name) {
        return userDao.queryUserByName(name);
    }

    //保存一个用户
    public void save(User user){
        int initId=userDao.queryUserNum();

        if(user.getId()==null) {
            initId++;
            user.setId(initId);
        }

        userDao.addUser(user);
    }

}
